import Vue from "vue";
import VueSweetalert2 from "vue-sweetalert2";

import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import "font-awesome/css/font-awesome.min.css";
// animate动画库
import "animate.css";
import "./style/global.css";

import App from "./App";
import router from "./router";
import store from "./store";

// 自定义的全局组件
import Notification from "@/components/notification";

// 国际化
import i18n from "./lang";
// 全局权限检查
import "./permission";
// 全局图标
import "./icons";
// 全局 Mock 接口
import "./mock";
import { SUCCESS_CODE, OP_SUCCESS, OP_FAIL } from "./config/config";

Vue.use(VueSweetalert2);

Vue.use(ElementUI, {
  size: "medium",
  i18n: (key, value) => i18n.t(key, value)
});
Vue.use(Notification);
Vue.mixin({
  methods: {
    getTableHeight(offset) {
      let viewHeight = document.documentElement.clientHeight;
      if (offset) {
        return viewHeight - offset;
      }
      return viewHeight - 100;
    },
    handleOpSuccess(result) {
      if (result.status === SUCCESS_CODE) {
        this.$swal(OP_SUCCESS, "", "success");
      } else {
        if (result && result.msg) {
          this.$swal(result.msg, "", "error");
        } else {
          this.$swal(OP_FAIL, "", "error");
        }
      }
    },
    alertInfo(title) {
      let cfg = {
        allowOutsideClick: false,
        showConfirmButton: true,
        confirmButtonText: '确定',
        showCancelButton: true,
        cancelButtonText: '取消'
      }
      if (title instanceof Object) {
        cfg = Object.assign(cfg, title)
      } else {
        cfg.title = title;
      }
      return this.$swal(cfg)
    },
    clearObj(obj) {
      Object.keys(obj).forEach(key => {
        switch (typeof obj[key]) {
          case 'string':
            obj[key] = '';
            break;
          case 'number':
            obj[key] = 0
            break
          default:
            break;
        }
      })
    },
    clearEmptyParams(params) {
      // 删除空参数
      Object.keys(params).forEach(key => {
        if (params[key] === null || params[key] === undefined || params[key] === '') {
          delete params[key]
        }
      });
      return params;
    }
  }
});

Vue.config.productionTip = false;

/* eslint-disable no-new */
new Vue({
  el: "#app",
  router,
  store,
  i18n,
  render: h => h(App)
});
